#include "reg51.h"

#define ADDR0 P1_0
#define ADDR1 P1_1
#define ADDR2 P1_2
#define ADDR3 P1_3
#define ENLED P1_4

int main() {
    char cnt = 0;
    unsigned char direction = 0;

    ENLED = 0;
    ADDR3 = 1;
    ADDR2 = 1;
    ADDR1 = 1;
    ADDR0 = 0;

    while (1) {
        if (direction == 0) {
            // 从左向右
            P0 = ~(0x01 << cnt);
            cnt++;
            if (cnt >= 8) {
                cnt = 1;
                direction = 1;
            }
        } else {
            // 从右向左
            P0 = ~(0x80 >> cnt);
            cnt++;
            if (cnt >= 8) {
                cnt = 1;
                direction = 0;
            }
        }
        for (int i = 0; i < 20000; ++i);
    }

}
